// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-9-23

#include "stdafx.h"
#include ".\useravatar.h"
#include <common/ui/htmlview.h>
#include "userlist.h"

extern CHAR joy_url_useravarta[];

//##ModelId=44C4B5DA0020
CJoyUserAvatar::CJoyUserAvatar(void)
{
    m_avatarView = NULL;
    m_align = AT_Client;
    m_avatarSize    = 180;
    m_name = "avatar";
}

//##ModelId=44C4B5DA0022
CJoyUserAvatar::~CJoyUserAvatar(void)
{
}

//##ModelId=44C4B5DA0025
void CJoyUserAvatar::SetUserItem(CJoyUserItem* pItem)
{
    UINT userId = (pItem != NULL) ? pItem->m_userId : 0;

    char szUrl[256];
    sprintf(szUrl, "%s%d", joy_url_useravarta, userId);

    m_avatarView->GetHtmlView()->Navigate(szUrl);
}

BEGIN_MESSAGE_MAP(CJoyUserAvatar, CJoyWnd)
    ON_WM_CREATE()
    ON_WM_SIZE()
END_MESSAGE_MAP()

//##ModelId=44C4B5DA002E
void CJoyUserAvatar::CM_LoadSkin(CJoyXmlElement* pSkinElem)
{
    m_avatarSize = pSkinElem->ReadIntD("avatar_size", m_avatarSize);
    __super::CM_LoadSkin(pSkinElem);
}

//##ModelId=44C4B5DA0031
int CJoyUserAvatar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CJoyWnd::OnCreate(lpCreateStruct) == -1)
        return -1;

    m_avatarView = new CJoyHtmlPanel();
    //m_avatarView->SetAlign(AT_Client);
    m_avatarView->Create(this, CRect(0, 0, 10, 10));
//#ifndef _DEBUG
    m_avatarView->GetHtmlView()->Navigate(joy_url_useravarta);
//#endif

    return 0;
}

//##ModelId=44C4B5DA0034
void CJoyUserAvatar::OnSize(UINT nType, int cx, int cy)
{
    CJoyWnd::OnSize(nType, cx, cy);

    //int top = (cy-m_avatarSize)/2;
    m_avatarView->SetArea(
        CRect(0, 0, cx, m_avatarSize));
}
